import { createApp } from 'vue'
import ElementPlus from 'element-plus'
// import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/src/index.scss'
// 全局组件
import gloablComponent from './components'
// 引入App
// import App from '../contentScript/default_popup/App.vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// 引入图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 引入svg
import 'virtual:svg-icons-register'
import { createPinia } from 'pinia'
import { toAnyString } from '../utils'

const pinia = createPinia()
//挂载函数
function createVueApp(parentElement: any, App: any) {
    const app = document.createElement('div')
    app.setAttribute('id', 'google-plugin-app-' + toAnyString())
    parentElement.appendChild(app)
    const appInstance = createApp(App)
    // 挂载全局Element组件
    appInstance.use(ElementPlus, { locale: zhCn, size: 'small' })
    // 挂载全局组件
    appInstance.use(gloablComponent)
    // 挂载pinia
    appInstance.use(pinia)
    // 挂载图标
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
        appInstance.component(key, component)
    }
    // 挂载app
    appInstance.mount(app)
}

export { createVueApp }
